set loop_count 0

proc tarai {x y z} {
    global loop_count
    incr loop_count
    if {$y < $x} {
	return [tarai \
                    [tarai [expr $x - 1] $y $z] \
                    [tarai [expr $y - 1] $z $x] \
                    [tarai [expr $z - 1] $x $y]]
    }
    return $y
}

puts [tarai 12 6 0]
puts $loop_count
